<?php
if (!isset($thinkwiki))
{
	die('Hacking Attempt!');
}

if (!file_exists('./include/config.php'))
{
	header('Location: ./install/index.php');
	// Just in case:
	exit;
}
include('./include/config.php');

$conn = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname);

$sql = "SELECT * FROM config";
$result = mysql_query($sql);
$config = mysql_fetch_array($result);

if (isset($_COOKIE['thinkwiki_user']))
{
	setcookie('thinkwiki_user', $_COOKIE['thinkwiki_user'], time()+3600);
	$sql = "SELECT * FROM users WHERE user_id='" . $_COOKIE['thinkwiki_user'] . "'";
	$result = mysql_query($sql);
	$num_rows = mysql_num_rows($result);
	if ($num_rows == 0)
	{
		// The cookie may be fake. The user is not logged in. Let's unset the cookie.
		setcookie('thinkwiki_user', $_COOKIE['thinkwiki_user'], time()-1);
		$sql = "SELECT * FROM users WHERE user_id='1'";
		$result = mysql_query($sql);
		$userdata = mysql_fetch_array($result);
	}
	else
	{
		$userdata = mysql_fetch_array($result);	
	}
}
else
{
	$sql = "SELECT * FROM users WHERE user_id='1'";
	$result = mysql_query($sql);
	$userdata = mysql_fetch_array($result);
}
?>